# from pymysql import connect, cursors
#
# # 数据库配置参数
# USERNAME = 'root'
# PASSWORD = 'jisuanji2022'
# HOST = '121.196.166.117'
# PORT = 3306
# DATABASE = "woniunote"
#
#
# # 连接数据库并执行SQL查询的函数
# def query_data(sql_str):
#     try:
#         # 连接数据库
#         conn = connect(
#             user=USERNAME,
#             password=PASSWORD,
#             host=HOST,
#             port=PORT,
#             database=DATABASE,
#             cursorclass=cursors.DictCursor  # 指定游标类型为DictCursor
#         )
#
#         # 获取游标对象
#         cur = conn.cursor()
#
#         # 使用游标对象来执行SQL语句
#         row_count = cur.execute(sql_str)
#
#         # 提交修改数据的SQL语句到数据库
#         conn.commit()
#
#         # 使用游标对象获取查询结果
#         result = cur.fetchall()
#
#     except Exception as e:
#         print(f"An error occurred: {e}")
#         result = None  # 发生异常时返回None
#
#     finally:
#         # 关闭游标
#         if cur:
#             cur.close()
#
#         # 断开与数据库的连接
#         if conn:
#             conn.close()
#
#     return result
#

# 可以添加更多的数据库操作方法，例如插入、更新、删除等

article_type = {
    1:'PHP开发',
    2:'Java开发',
    3:'python开发',
    4:'web前端',
    5:'测试开发',
    6:'数据科学',
    7:'网络安全',
    8:'蜗牛杂谈'
}


class ArticleUtil:
    def __init__(self):
        pass

    @staticmethod
    def transfrom_type(article):
        article['type'] = article_type[article.get('type')]
        return article

    @staticmethod
    def transfrom_date(article):
        article['createtime'] = article['createtime'].strftime('%Y-%m-%d %H:%M:%S')
        article['updatetime'] = article['updatetime'].strftime('%Y-%m-%d %H:%M:%S')
        return article

    @staticmethod
    def transfrom_article(article_list):
        for article in article_list:
            article = ArticleUtil.transfrom_type(article)
            article = ArticleUtil.transfrom_date(article)
        return article_list